<template>
  <div>
    <input
      type="text"
      placeholder="请输入任务名称，按回车确认"
      v-model="inputValue"
      @keyup.enter="addTaskObj"
    />
  </div>
</template>

<script>
export default {
  name: "MyHeader",
  data() {
    return {
      inputValue: "",
    };
  },
  methods: {
    addTaskObj() {
      if (this.inputValue === "") {
        alert("请输入任务名称");
        return;
      }
      this.addTask({
        id: Date.now(),
        name: this.inputValue,
        done: false,
      });
      this.inputValue = "";
    },
  },
  props: ["addTask"],
};
</script>

<style>
</style>